using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the SiteUserDetail class.
	/// </summary>
	[Serializable]
	public partial class SiteUserDetailCollection : ActiveList<SiteUserDetail, SiteUserDetailCollection> 
	{	   
		public SiteUserDetailCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the SiteUserDetail table.
	/// </summary>
	[Serializable]
	public partial class SiteUserDetail : ActiveRecord<SiteUserDetail>
	{
		#region .ctors and Default Settings
		
		public SiteUserDetail()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public SiteUserDetail(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public SiteUserDetail(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public SiteUserDetail(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("SiteUserDetail", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarUserDetailID = new TableSchema.TableColumn(schema);
				colvarUserDetailID.ColumnName = "UserDetailID";
				colvarUserDetailID.DataType = DbType.Int64;
				colvarUserDetailID.MaxLength = 0;
				colvarUserDetailID.AutoIncrement = true;
				colvarUserDetailID.IsNullable = false;
				colvarUserDetailID.IsPrimaryKey = true;
				colvarUserDetailID.IsForeignKey = false;
				colvarUserDetailID.IsReadOnly = false;
				colvarUserDetailID.DefaultSetting = @"";
				colvarUserDetailID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserDetailID);
				
				TableSchema.TableColumn colvarSiteUserID = new TableSchema.TableColumn(schema);
				colvarSiteUserID.ColumnName = "SiteUserID";
				colvarSiteUserID.DataType = DbType.Int32;
				colvarSiteUserID.MaxLength = 0;
				colvarSiteUserID.AutoIncrement = false;
				colvarSiteUserID.IsNullable = false;
				colvarSiteUserID.IsPrimaryKey = false;
				colvarSiteUserID.IsForeignKey = false;
				colvarSiteUserID.IsReadOnly = false;
				colvarSiteUserID.DefaultSetting = @"";
				colvarSiteUserID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSiteUserID);
				
				TableSchema.TableColumn colvarLoginDate = new TableSchema.TableColumn(schema);
				colvarLoginDate.ColumnName = "LoginDate";
				colvarLoginDate.DataType = DbType.DateTime;
				colvarLoginDate.MaxLength = 0;
				colvarLoginDate.AutoIncrement = false;
				colvarLoginDate.IsNullable = true;
				colvarLoginDate.IsPrimaryKey = false;
				colvarLoginDate.IsForeignKey = false;
				colvarLoginDate.IsReadOnly = false;
				colvarLoginDate.DefaultSetting = @"";
				colvarLoginDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLoginDate);
				
				TableSchema.TableColumn colvarIpAddress = new TableSchema.TableColumn(schema);
				colvarIpAddress.ColumnName = "IpAddress";
				colvarIpAddress.DataType = DbType.String;
				colvarIpAddress.MaxLength = 50;
				colvarIpAddress.AutoIncrement = false;
				colvarIpAddress.IsNullable = true;
				colvarIpAddress.IsPrimaryKey = false;
				colvarIpAddress.IsForeignKey = false;
				colvarIpAddress.IsReadOnly = false;
				colvarIpAddress.DefaultSetting = @"";
				colvarIpAddress.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIpAddress);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("SiteUserDetail",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("UserDetailID")]
		public long UserDetailID 
		{
			get { return GetColumnValue<long>("UserDetailID"); }

			set { SetColumnValue("UserDetailID", value); }

		}

		  
		[XmlAttribute("SiteUserID")]
		public int SiteUserID 
		{
			get { return GetColumnValue<int>("SiteUserID"); }

			set { SetColumnValue("SiteUserID", value); }

		}

		  
		[XmlAttribute("LoginDate")]
		public DateTime? LoginDate 
		{
			get { return GetColumnValue<DateTime?>("LoginDate"); }

			set { SetColumnValue("LoginDate", value); }

		}

		  
		[XmlAttribute("IpAddress")]
		public string IpAddress 
		{
			get { return GetColumnValue<string>("IpAddress"); }

			set { SetColumnValue("IpAddress", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varSiteUserID,DateTime? varLoginDate,string varIpAddress)
		{
			SiteUserDetail item = new SiteUserDetail();
			
			item.SiteUserID = varSiteUserID;
			
			item.LoginDate = varLoginDate;
			
			item.IpAddress = varIpAddress;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(long varUserDetailID,int varSiteUserID,DateTime? varLoginDate,string varIpAddress)
		{
			SiteUserDetail item = new SiteUserDetail();
			
				item.UserDetailID = varUserDetailID;
				
				item.SiteUserID = varSiteUserID;
				
				item.LoginDate = varLoginDate;
				
				item.IpAddress = varIpAddress;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string UserDetailID = @"UserDetailID";
			 public static string SiteUserID = @"SiteUserID";
			 public static string LoginDate = @"LoginDate";
			 public static string IpAddress = @"IpAddress";
						
		}

		#endregion
	}

}

